package com.edais.actions;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.edais.service.SpringFestivalService;
import com.yunzhi.domain.RequestHeader;
import com.yunzhi.domain.ResultCode;
import com.yunzhi.domain.ResultConstant;
import com.yunzhi.domain.ResultDTO;
import com.yunzhi.util.RequestUtil;
import com.yunzhi.util.ResponseUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * ClassName: SpringFestivalAction 
 * @Description: 页面展示图标
 * @author 郭栋
 * @date 2016-12-14
 */

@Controller
@RequestMapping("/springFestival")
public class SpringFestivalAction  implements Serializable{

	private static final long serialVersionUID = 1L;

	private static final Log logger = LogFactory.getLog(SpringFestivalAction.class);

	@Autowired
	private SpringFestivalService springFestivalService;
	
	/**
	 * @Description: 获取初始化图标
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws Exception
	 * @author guodong
	 * @date 2016-12-14
	 */
	@RequestMapping(value = "/springFestivalIcon")
	public void springFestivalIcon(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//签名校验
		if (!RequestUtil.validSign(request)) {
			logger.info("无效签名");
			ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
			return;
		}
		ResultDTO resultDTO;
		RequestHeader header = RequestUtil.decodeHeader(request);
		logger.info("header：" + header.toString());
		JSONObject paramsMap = RequestUtil.decodeDataJson(request);
		logger.info("data：" + paramsMap.toString());

		String flag = paramsMap.getString("flag");//校验标识
		String marks = paramsMap.getString("marks");//微信、app区分标识
			if (StringUtils.isBlank(flag)&&!"lbjrcjtb".equals(flag)) {
				logger.error("获取初始化图标：flag为空");
				resultDTO=new ResultDTO(ResultCode.FAILED,"flag为空！");
				// 处理返回结果
				ResponseUtil.write(response,resultDTO);
				return;
			}

			if (StringUtils.isBlank(marks)&&!"weixin".equals(marks)) {
				logger.info("获取初始化图标：marks为空");
				resultDTO=new ResultDTO(ResultCode.FAILED,"marks为空！");
				// 处理返回结果
				ResponseUtil.write(response,resultDTO);
				return;
			}
			Map<String, Object> parmeterMap = new HashMap<String, Object>();

			/*if ("weixin".equals(marks)) {
				resultDTO = springFestivalService.getWxSpringFestivalIcon(parmeterMap);
			}else {
				resultDTO = springFestivalService.getSpringFestivalIcon(parmeterMap);
			}*/
			resultDTO = springFestivalService.getSpringFestivalIcon(parmeterMap);

			ResponseUtil.write(response,  resultDTO);
	}

}
